package com.hly.baseactivity

import android.os.Bundle
import android.widget.Toast
import androidx.core.content.ContextCompat
import com.hly.baseactivity.databinding.MainActivityBinding

class MainActivity : BaseActivity<MainActivityBinding, MainViewModel>() {

    override fun initViewBinding(): MainActivityBinding  = MainActivityBinding.inflate(layoutInflater)

    override fun initData() {
            binding.button.setOnClickListener {
                Toast.makeText(this, "点击了按钮", Toast.LENGTH_SHORT).show()
            }
    }

    override fun initView(savedInstanceState: Bundle?) {
            viewModel.loadData()
            viewModel.data.observe(this) { ButtonDataBean ->
            binding.apply {
                button.text = ButtonDataBean.text
                button.setBackgroundColor(ContextCompat.getColor(root.context, ButtonDataBean.backgroundColor))
                button.setTextSize(ButtonDataBean.textSize)
                button.setTextColor(ContextCompat.getColor(root.context, ButtonDataBean.textColor))

            }
        }
    }

    override fun initViewModel(): Class<MainViewModel>  = MainViewModel::class.java
}